/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util.Autocomplete;

/**
 *
 * @author Joao
 */
import banco.ConexaoBD;
import banco.UsuarioDAO;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;

@ManagedBean(name = "autoCompleteBean")
@SessionScoped
public class AutoCompleteBean {

    private String selectedProfessor;
    private List<String> professores;
    private String[][] vetorProfessores;

    UsuarioDAO banco = new UsuarioDAO(ConexaoBD.getConexaoBD());

    public AutoCompleteBean() throws SQLException {

        vetorProfessores = banco.getProfessorsNames();

        professores = new ArrayList<String>();

        System.out.println("Tamanho " + vetorProfessores[0]);

        for(int i = 1; i < vetorProfessores.length; i++){
            professores.add(vetorProfessores[i][0] + " (" + vetorProfessores[i][1] + ")");
            System.out.println("Nome " + vetorProfessores[i][0]);
        }

        //professores.add(new Professor("Pedro", 481522842));
        professores.add("Messi");
        professores.add("Ibrahimovic");
        professores.add("Henry");
        professores.add("Iniesta");
        professores.add("Xavi");
        professores.add("Puyol");
    }

    public String getSelectedProfessor() {
        return selectedProfessor;
    }

    public void setSelectedProfessor(String selectedProfessor) {
        this.selectedProfessor = selectedProfessor;
    }

    public List<String> completePlayer(String query) {

        List<String> suggestions = new ArrayList<String>();

        for (String p : professores) {

            if (p.startsWith(query)) {
                suggestions.add(p);
            }
        }
        return suggestions;
    }
}
